﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Web.UI.WebControls;

/// <summary>
/// function 的摘要说明
/// </summary>
public class func
{
    public func()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    //普通用户---------------------------------------------------------------------------------------------------
    //用户登录表***************************************************************************************************
    public static bool ishave(string usr)//判断是否有此账号
    {
        bool a = false;
        string sql = "select count(*) from usr_login where usr_id='"+usr+"'";
        sqlhelper.conn.Open();
        if(sqlhelper.getsclar(sql)>0)
        {
            a = true;
        }
        sqlhelper.conn.Close();
        return a;

    }
    public static bool Login_usr(string usr, string code)//验证普通用户登录
    {

        string sql = "select count(*) from usr_login where usr_id='" + usr + "' and usr_pad='" + code + "' ";

        sqlhelper.conn.Open();
        bool a = false;
        if (sqlhelper.getsclar(sql) > 0)
        {
            a = true;
        }
        sqlhelper.conn.Close();
        return a;

    }
    public static bool res(string usr, string cod, string phone, string email)
    {
        bool a = false;
        string sql = "insert into usr_login(usr_id,usr_pad,usr_phone,usr_email) values('" + usr + "','" + cod + "','" + phone + "','" + email + "')";
        sqlhelper.conn.Open();
        if (sqlhelper.getnonquery(sql) > 0)
        {
            a = true;
        }
        sqlhelper.conn.Close();
        return a;
    }
    public static bool istrue(string usr, string phone, string email)
    {
        bool a = false;
        string sql = "select count(*) from usr_login where usr_id='" + usr + "' and usr_phone='" + phone + "' and usr_email='" + email + "'";
        sqlhelper.conn.Open();
        if (sqlhelper.getsclar(sql) > 0)
        {
            a = true;
        }
        sqlhelper.conn.Close();
        return a;
    }
    public static string getcode(string usr, string phone, string email)
    {
        string code = null;
        string sql = "select * from usr_login where usr_id='" + usr + "' and usr_phone='" + phone + "' and usr_email='" + email + "'";
        sqlhelper.conn.Open();

        SqlDataReader sdr = sqlhelper.sreader(sql);
        while (sdr.Read())
        {
            code = sdr[1].ToString();

        }
        sdr.Close();
        sqlhelper.conn.Close();
        return code;
    }
    public static bool upcod(string usr, string qrnewcod)
    {

        bool a = false;
        sqlhelper.conn.Open();
        string sql = "update usr_login set usr_pad='" + qrnewcod + "' where usr_id='" + usr + "'";
        if (sqlhelper.getnonquery(sql) > 0)
        {
            a = true;
        }
        sqlhelper.conn.Close();
        return a;
    }
    //***********************************************************************************************************
    //用户信息表***********************************************************************************************
    public static bool czje(string usr,int money)
    {
        bool a = false;
        sqlhelper.conn.Open();
        string sql = "update usr_infor set amount="+money+" where id='" + usr + "'";
        if(sqlhelper.getnonquery(sql)>0)
        {
            a = true;
        }
        sqlhelper.conn.Close();
        return a;

    }
   
    //插入普通用户信息
    public static bool ins_infor(string usr_id,string xm,string xb,string jg,string idcard,int m)
    {
        bool a = false;
        string sql = "insert into usr_infor values('"+usr_id+"','"+xm+"','"+xb+"','"+jg+"','"+idcard+"',"+m+")";
        sqlhelper.conn.Open();
        if(sqlhelper.getnonquery(sql)>0)
        {
            a = true;
        }
        sqlhelper.conn.Close();
        return a;
    }
    //普通用户表是否有信息
    public static bool isinfor(string usr_id)
    {
        bool a = false;
        string sql = "select count(*) from usr_infor where id='" + usr_id + "'";
        sqlhelper.conn.Open();
        if(sqlhelper.getsclar(sql)>0)
        {
            a = true;
        }
        sqlhelper.conn.Close();
        return a;

    }
    public static DataSet ds(string usr_id)
    {
        string sql="select * from usr_infor where id='"+usr_id+"'";       
        SqlDataAdapter mda = new SqlDataAdapter(sql,sqlhelper.conn);
        DataSet ds1=new DataSet();
        mda.Fill(ds1);
        return ds1;
    }

    //*********************************************************************************************************
    //订房信息表**********************************************************************************************
    //public static bool isorder(string usr)
    //{
    //    bool a = false;
    //    string osr = "是";
    //    string sql = "select COUNT(*) from oroominfor where id='" + usr + "' and isorder='"+osr+"'";
    //    sqlhelper.conn.Open();
    //    if(sqlhelper.getsclar(sql)>0)
    //    {
    //        a = true;
    //    }
    //    sqlhelper.conn.Close() ;
    //    return a;
    //}
    //结算时更改数据*************************************************************************************
    public static bool jsdel(string usr)
    {
        bool a = false;
        string sql = "delete oroominfor where id='"+usr+"'";
        sqlhelper.conn.Open();
        if (sqlhelper.getnonquery(sql)> 0)
        {
            a = true;
        }
        sqlhelper.conn.Close();
        return a;
    }
    //***************************************************************************************************
    //订房信息是否有数据
    public static bool isordinfor(string usr)
    {
        bool a = false;
        sqlhelper.conn.Open();
        string sql = "select count(*) from oroominfor where id='" + usr + "'";
        if (sqlhelper.getsclar(sql) > 0)
        {
            a = true;
        }
        sqlhelper.conn.Close();
        return a;
    }
    //********************************************************************************************************************
    //订房信息查询***********************************************************************************************************
    public static DataSet oderinfor(string usr)
    {
        string sql = "select usr_infor.name,oroominfor.* from usr_infor,oroominfor where usr_infor.id=oroominfor.id and oroominfor.id='" + usr+"'";
        SqlDataAdapter mda = new SqlDataAdapter(sql,sqlhelper.conn);
        DataSet ds = new DataSet();
        mda.Fill(ds);
        return ds;
       
    }
    //修改订房信息表
    public static bool updroominfor(string usr,int day,int roomid, string type,int rmonry,int allmoney)
    {
        
        string sql = "insert into oroominfor values('"+usr+"','是',"+day+",'"+type+"',"+rmonry+","+allmoney+","+roomid+")";
        bool a = false;
        sqlhelper.conn.Open();
        if (sqlhelper.getnonquery(sql) > 0)
        {
            a = true;
        }
        sqlhelper.conn.Close();
        return a;

    }
    //******++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //管理员---------------------------------------------------------------------------------------------------------------
    //管理员登陆表******************************************************************************************************************
    public static bool Login_admir(string usr, string code)
    {

        string sql = "select count(*) from admir_login where admir_name='" + usr + "' and admir_pad='" + code + "' ";

        sqlhelper.conn.Open();
        bool a = false;
        if (sqlhelper.getsclar(sql) > 0)
        {
            a = true;
        }
        sqlhelper.conn.Close();
        return a;

    }
   
    
    public static bool isadmtrue(string usr, string vid)
    {
        bool a = false;
        string sql = "select count(*) from admir_login where admir_name='" + usr + "'  and admir_no='" + vid + "'";
        sqlhelper.conn.Open();
        if (sqlhelper.getsclar(sql) > 0)
        {
            a = true;
        }
        sqlhelper.conn.Close();
        return a;
    }
    //找回密码
    public static string getadmcode(string usr, string vid)
    {
        string code = null;
        string sql = "select * from admir_login where admir_name='" + usr + "'  and admir_no='" + vid + "'";
        sqlhelper.conn.Open();
        SqlDataReader sdr = sqlhelper.sreader(sql);
        while (sdr.Read())
        {
            code = sdr[1].ToString();

        }
        sdr.Close();
        sqlhelper.conn.Close();
        return code;
    }
    //是否为管理员 
    public static bool isadmir(string s)
    {
        bool a = false;
        string sql = "select count(*) from admir_login where admir_name='"+s+"'";
        sqlhelper.conn.Open();
        if (sqlhelper.getsclar(sql)>0)
        {
            a = true;
        }
        sqlhelper.conn.Close();
        return a;
    }
    //显示图片
    public static DataSet dispic(string drp1)
    {
        string sql = "select * from rtype where rname='"+drp1+"'";
        SqlDataAdapter mda = new SqlDataAdapter(sql,sqlhelper.conn);
        DataSet ds = new DataSet();
        mda.Fill(ds);
        return ds;
    }
    //显示空房
    public static DataSet ERoomInfor(string RT)
    {
        string sql = "select * from HM_RoomCategory,HM_RoomStatus where HM_RoomCategory.HM_RCategoryId=HM_RoomStatus.HM_RCategoryId and HM_RoomStatus.HM_RStatus=1 and HM_RName='"+RT+"'";
        SqlDataAdapter mdr = new SqlDataAdapter(sql,sqlhelper.conn);
        DataSet ds = new DataSet();
        mdr.Fill(ds);
        return ds;
    }

    //更改房间状态，始1
    public static bool updstatus(int id,int status)
    {
        string sql = "update HM_RoomStatus set HM_RStatus ="+status+"  where HM_RCategoryId="+id+"";
        bool a = false;
        sqlhelper.conn.Open();
        if(sqlhelper.getnonquery(sql)>0)
        {
            a = true;
        }
        sqlhelper.conn.Close();
        return a;
    }
    //gridview为空提示
    public static string EmptyText = "该类型房间已无空房，非常抱歉";
    public static void GridViewDataBind(GridView gridview, DataTable table)
    {
       
        if (table.Rows.Count == 0)
        {
            table = table.Clone();
            table.Rows.Add(table.NewRow());
            gridview.DataSource = table;
            gridview.DataBind();
            int count = table.Columns.Count;
            gridview.Rows[0].Cells.Clear();
            gridview.Rows[0].Cells.Add(new TableCell());
            gridview.Rows[0].Cells[0].ColumnSpan = count;
            gridview.Rows[0].Cells[0].Text = EmptyText;
            gridview.Rows[0].Cells[0].Style.Add("text-align", "center");
            gridview.Rows[0].Cells[0].Style.Add("color", "red");
        }
        else
        {
            gridview.DataSource = table;
            gridview.DataBind();
        }
        gridview.SelectedIndex = -1;
    }
    //public static void DDLContrls(DropDownList drpdl,DataTable table,string DTF)
    //{
    //    if (table.Rows.Count == 0)
    //    {
    //        drpdl.SelectedValue =EmptyText;
    //    }
    //    else
    //    {
    //        drpdl.DataSource = table;
    //        drpdl.DataTextField = "+DTF+";
    //        drpdl.DataBind();
    //    }
    //    drpdl.SelectedIndex = -1;
    //}


}
